package cn.chencq.utils;

import java.util.Random;

public class RandomUtils {

	public static String getLoginPassword() {
		int len = getRandNum(6, 12);
		return getStringRandom(len);
	}

	/**
	 * 随机生成6位数字
	 */
	public static String getWithdrawPassword() {
		int num = getRandNum(100000, 999999);
		return String.valueOf(num);
	}

	public static int getRandNum(int min, int max) {
		int randNum = min + (int) (Math.random() * ((max - min) + 1));
		return randNum;
	}

	/**
	 * 
	 * @Title: getStringRandom
	 * @Description: 随机生成指定长度的（包括数字和字母）
	 * @param length
	 * @return String
	 */
	public static String getStringRandom(int length) {
		String val = "";
		Random random = new Random();
		// length为几位密码
		for (int i = 0; i < length; i++) {
			String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
			// 输出字母还是数字
			if ("char".equalsIgnoreCase(charOrNum)) {
				// 输出是大写字母还是小写字母
				int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
				val += (char) (random.nextInt(26) + temp);
			} else if ("num".equalsIgnoreCase(charOrNum)) {
				val += String.valueOf(random.nextInt(10));
			}
		}
		return val;
	}
}
